<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setAttribute("basePath", basePath);
String baseInfoJson= (String)request.getAttribute("baseInfoJson");
String diseaseDiagInfoJson= (String)request.getAttribute("diseaseDiagInfoJson");
String respondResultJson= (String)request.getAttribute("respondResultJson");
%>
<link rel="stylesheet" href="${basePath}assets/bootstrap/css/bootstrap.css"/>
<link rel="stylesheet" href="${basePath}assets/css/basic.css"/>
<link rel="stylesheet" href="${basePath}assets/jquery-ui/jquery-ui.css"/>
<link rel="stylesheet" href="${basePath}assets/css/medical_record/home_page.css"/>
<script type="text/javascript" src="${basePath}assets/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/layer/layer.js"></script>
<script type="text/javascript" src="${basePath}assets/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="${basePath}assets/jquery-ui/jquery-ui.js"></script>
<script type="text/javascript" src="${basePath}assets/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${basePath}assets/js/medical_record/edit_diag_info.js"></script>
<link href="${basePath}/static/layer/layer_defined.css" rel="stylesheet" type="text/css">

<input type="hidden" id="basePath" value="${basePath }"/>
<form id="diagForm" action="${basePath}medical_record/edit_home_page_diag"
	method="post" style="height:100%;overflow-y:auto;overflow-x:hidden;">
	<input type="hidden" name="visitGuid" value="${visitGuid }">
	<input type="hidden" id="age" name="age" value="${age }">
	<input type="hidden" id="sexName" name="sexName" value="${sexName}">
	<input type="hidden" value="0" id="diseaseDiagCount" />
	<input type="hidden" value="${basePath }" id="basePath" />
	<!-- <div style="height:700px; overflow-y:auto;overflow-x:hidden"> -->
		<table style="margin:0 auto;" id="diseaseDiagTable" >
		
			<thead>
				<tr>
					<td colspan="9">
						<div style="float:right">
							<input type="button" value="保存"  id="zongAdd" class="btn"> <input
								type="button" value="新增" onclick="addDiseaseDiagRecord()"
								class="btn">
						</div>
					</td>
				</tr>
				
				<tr>
					<td class="tdLabel_4 redColor" width="12%">诊断类型*</td>
					<td class="tdLabel_4" width="20%">原始描述</td> 
					<td class="tdLabel_4 redColor" width="24%">疾病编码*</td>
				<!--    <td class="tdLabel_4" width="20%">病理编码</td>  -->
					<td class="tdLabel_4" width="11%">治疗结果</td>
					<td class="tdLabel_4" width="17%">确诊日期</td>
					<td class="tdLabel_4" width="4%">治疗天数</td>
					<td class="tdLabel_4" width="11%">手术治疗</td>
					<td class="tdLabel_4" width="3%">位序</td>
					<td class="tdLabel_4" width="4%">操作</td>
				</tr>
				</thead>
				<tbody>
				
				</tbody>
				<tfoot>
					<tr>
						<td align="left" style="height:80px;" class="tdLabel_8" colspan="9"></td>
					</tr>
					
				</tfoot>
		</table>
	<!-- </div> -->
	
</form>

<table hidden="true">
	<tr id="templateDiseaseDiagTr">
		<td class="tdLabel_8">
			<select name="diseaseDiagRecords[0].diagTypeCode" style="width: 100%" class="diagTypeSelect">
			</select>
			<input type="hidden" name="diseaseDiagRecords[0].diagTypeName" />
		</td>
		  <td  class="tdLabel_8">
			<input type="text" name="diseaseDiagRecords[0].diseaseDiagOriginalDesc" style="width: 100%" readonly="readonly">
		</td> 
		<!-- <input type="hidden" name="diseaseDiagRecords[0].diseaseDiagOriginalDesc" style="width: 100%" readonly="readonly"> -->
		<td class="tdLabel_8">
			<input class="input_box diseaseDiagSearchInput diagICDName" type="text" name="diseaseDiagRecords[0].diseaseDiagName">
			<input type="hidden" name="diseaseDiagRecords[0].diseaseDiagCode" class="diagICDCode">
		</td>
		<!-- <td class="tdLabel_8">
			<input class="input_box" type="text" name="">
			<input type="hidden" name="">
		</td>  -->
		
		<td class="tdLabel_8">
			<select name="diseaseDiagRecords[0].treatResultCode" style="width: 100%" class="treatResultSelect">
			</select>
			<input type="hidden" name="diseaseDiagRecords[0].treatResultName">
		</td>
		<td class="tdLabel_8">
			<input class="input_box" name="diseaseDiagRecords[0].confirmedDateTime" type="text" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
		</td>
		<td class="tdLabel_8">
			<input class="input_box" type="text" name="diseaseDiagRecords[0].treatDayNumber">
		</td>
		<td class="tdLabel_8">
			<select name="diseaseDiagRecords[0].operateMarkCode" style="width: 100%" class="operateMark">
			</select>
			<input type="hidden" name="diseaseDiagRecords[0].operateMarkName">
		</td>
		<td class="tdLabel_8">
			<input class="input_box" type="text" name="diseaseDiagRecords[0].diagSortIndex" class="diagSortIndex">
		</td>
		<td class="tdLabel_8">
			<a style="padding:4px;margin:0 auto;" onclick="deleteDiseaseDiagRecord(this)" class="btn">删除</a>
		</td>
	</tr>
</table>
<script>
	$(function(){
		var baseInfoJson= <%=baseInfoJson%>;
		var diseaseDiagInfoJson= <%=diseaseDiagInfoJson%>;
		//console.log(baseInfoJson);
		//console.log(diseaseDiagInfoJson);
		initPage(baseInfoJson,diseaseDiagInfoJson);
		var respondResultJson= <%=respondResultJson%>;
		//console.log(respondResultJson);
		/* if(respondResultJson){
			if(respondResultJson.success){
				if(respondResultJson.stateCode = "200"){
					layer.msg(respondResultJson.stateMessage);
				}
			}else{
				if(respondResultJson.stateCode = "500"){
					layer.msg(respondResultJson.stateMessage);
				}
			}
		} */
		
	});
	
	
	//获取所有疾病信息判断是否可以进行编码合并
	$("#zongAdd").on("click",function(){
		var arr =[];
		//疾病类型和疾病编码不能为空
		var diagTypeSelect_arr=$("#diseaseDiagTable").find(".diagTypeSelect");
		
		var diseaseDiagName_arr=$('#diseaseDiagTable').find('.diagICDName');
		
		for(var i=0;i< diagTypeSelect_arr.length;i++){
		   var val=$(diagTypeSelect_arr[i]).val()
		   if(!val){
			   layer.alert('疾病诊断不能为空!',{icon:7});
			   return;
		   }
		}
	    for(var j=0;j<diseaseDiagName_arr.length;j++){
	      var val=$(diseaseDiagName_arr[j]).val();
	    
	      if(!val){
			   layer.alert('疾病编码不能为空!',{icon:7});
			   return;
		   }
		} 
	    
		$(".diagICDName").each(function(){
			arr.push($(this).val());
		})
		if(!arr){
			$("#diagForm").submit();
			return;
		}
		
		
		$.ajax({
			type:"post",
			data:{diagCodes:arr.toString()},
			url:"${basePath}/medrecord/validateDiagCodeBind",
			success:function(data){
				if(data.success){
					var msg = data.msg;
					
				     layer.confirm(msg, {
				            btn : [ '继续保存', '取消保存' ]//按钮
				        }, function(index) {
				        	$("#diagForm").submit();
				        }); 
					
					//$("#diagForm").submit();
				}else{
					$("#diagForm").submit();
				}
			}
		});
		
	});
	
	//保存按钮
	/* function Save(){
		console.log('save---------------');
		//疾病类型和疾病编码不能为空
		var diagTypeSelect_arr=$("#diseaseDiagTable").find(".diagTypeSelect");
		
		var diseaseDiagName_arr=$('#diseaseDiagTable').find('.diagICDName');
		console.log(diseaseDiagName_arr)
		for(var i=0;i< diagTypeSelect_arr.length;i++){
		   var val=$(diagTypeSelect_arr[i]).val()
		   if(!val){
			   layer.alert('疾病诊断不能为空!',{icon:7});
			   return;
		   }
		}
	    for(var j=0;j<diseaseDiagName_arr.length;j++){
	      var val=$(diseaseDiagName_arr[j]).val();
	      console.log()
	      if(!val){
			   layer.alert('疾病编码不能为空!',{icon:7});
			   return;
		   }
		} 
		$("#diagForm").submit();
		//return false;
	} */
</script>